home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Treiber / Misc / Mroocheck / FreeWheel / Source / ButtonWin.c < prev    next >
C/C++ Source or Header  |  2000-04-20  |  8KB  |  273 lines

  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. #include <exec/types.h>
  6. #include <intuition/intuition.h>
  7. #include <intuition/screens.h>
  8.  
  9. #include <clib/exec_protos.h>
  10. #include <clib/intuition_protos.h>
  11. #include <clib/gadtools_protos.h>
  12.  
  13. #include "Cx.h"
  14. #include "Prefs.h"
  15. #include "GUI.h"
  16. #include "WheelMouse.h"
  17.  
  18. #include "ButtonWin.h"
  19.  
  20. #define MIDCLICK_ID 1
  21. #define MIDCLICKROLL_ID 2
  22. #define MIDDOUBLECLICK_ID 3
  23. #define FOURTHCLICK_ID 4
  24. #define FOURTHCLICKROLL_ID 5
  25. #define FOURTHDOUBLECLICK_ID 6
  26.  
  27. BOOL ButtonWin_Show(struct ButtonWinContext *pwc);
  28. void ButtonWin_Hide(struct ButtonWinContext *pwc);
  29. BOOL ButtonWin_Handle(struct ButtonWinContext *pwc,unsigned long sigs);
  30. void ButtonWin_Dispose(struct ButtonWinContext *pwc);
  31.  
  32. extern struct WheelMouseContext *MyWM;
  33. extern struct CxContext *MyCx;
  34.  
  35. char *BWinGadTitles[]=
  36. {
  37.   "Middle button:",
  38.   "Fourth button:",
  39.   "Click:",
  40.   "Click + Roll:",
  41.   "Double Click:",
  42.   NULL
  43. };
  44.  
  45. #define MIDBUTTON_TITLE 0
  46. #define FOURTHBUTTON_TITLE 1
  47. #define CLICK_TITLE 2
  48. #define CLICKROLL_TITLE 3
  49. #define DOUBLECLICK_TITLE 4
  50.  
  51. BOOL ButtonWin_Show(struct ButtonWinContext *pwc)
  52. {
  53.   struct Gadget *gg;
  54.   int width,width2,leftedge,topedge;
  55.   int winleft,wintop;
  56.  
  57.   if(pwc->Visible)
  58.     return(FALSE);
  59.  
  60.   if(!(pwc->Screen=LockPubScreen(NULL)))
  61.     return(FALSE);
  62.  
  63.   if(!(pwc->GUI=GUI_Create(pwc->Screen,pwc->Screen->Font,8,8)))
  64.   {
  65.     pwc->Hide(pwc);
  66.     return(FALSE);
  67.   }
  68.  
  69.   GUI_StringTab(pwc->GUI,BWinGadTitles);
  70.  
  71.   width=GUI_MaxStringWidth(pwc->GUI,MyWM->MidButton.ClickModeNames);
  72.   width2=GUI_MaxStringWidth(pwc->GUI,MyWM->MidButton.DoubleClickModeNames);
  73.   if(width2>width) width=width2;
  74.   width2=GUI_MaxStringWidth(pwc->GUI,MyWM->MidButton.ClickRollModeNames);
  75.   if(width2>width) width=width2;
  76.  
  77.   pwc->GUI->InnerWidth=pwc->GUI->TabStop+width+64;
  78.  
  79.   /* Middle mouse button stuff */
  80.  
  81.   gg=GUI_BuildText(pwc->GUI,BWinGadTitles[MIDBUTTON_TITLE]);
  82.  
  83.   gg=GUI_BuildCycleGadget(pwc->GUI,BWinGadTitles[CLICK_TITLE],MyWM->MidButton.ClickModeNames,MIDCLICK_ID);
  84.   GT_SetGadgetAttrs(gg,NULL,NULL,GTCY_Active,
  85.                     pwc->Prefs->GetLong(pwc->Prefs,"MidClick",0),TAG_DONE);
  86.  
  87.   gg=GUI_BuildCycleGadget(pwc->GUI,BWinGadTitles[CLICKROLL_TITLE],MyWM->MidButton.ClickRollModeNames,MIDCLICKROLL_ID);
  88.   GT_SetGadgetAttrs(gg,NULL,NULL,GTCY_Active,
  89.                     pwc->Prefs->GetLong(pwc->Prefs,"MidCRoll",0),TAG_DONE);
  90.  
  91.   gg=GUI_BuildCycleGadget(pwc->GUI,BWinGadTitles[DOUBLECLICK_TITLE],MyWM->MidButton.DoubleClickModeNames,MIDDOUBLECLICK_ID);
  92.   GT_SetGadgetAttrs(gg,NULL,NULL,GTCY_Active,
  93.                     pwc->Prefs->GetLong(pwc->Prefs,"MidDClick",0),TAG_DONE);
  94.  
  95.   /* Fourth mouse button stuff */
  96.  
  97.   gg=GUI_BuildText(pwc->GUI,BWinGadTitles[FOURTHBUTTON_TITLE]);
  98.  
  99.   gg=GUI_BuildCycleGadget(pwc->GUI,BWinGadTitles[CLICK_TITLE],MyWM->FourthButton.ClickModeNames,FOURTHCLICK_ID);
  100.   GT_SetGadgetAttrs(gg,NULL,NULL,GTCY_Active,
  101.                     pwc->Prefs->GetLong(pwc->Prefs,"4thClick",0),TAG_DONE);
  102.  
  103.   gg=GUI_BuildCycleGadget(pwc->GUI,BWinGadTitles[CLICKROLL_TITLE],MyWM->FourthButton.ClickRollModeNames,FOURTHCLICKROLL_ID);
  104.   GT_SetGadgetAttrs(gg,NULL,NULL,GTCY_Active,
  105.                     pwc->Prefs->GetLong(pwc->Prefs,"4thCRoll",0),TAG_DONE);
  106.  
  107.   gg=GUI_BuildCycleGadget(pwc->GUI,BWinGadTitles[DOUBLECLICK_TITLE],MyWM->FourthButton.DoubleClickModeNames,FOURTHDOUBLECLICK_ID);
  108.   GT_SetGadgetAttrs(gg,NULL,NULL,GTCY_Active,
  109.                     pwc->Prefs->GetLong(pwc->Prefs,"4thDClick",0),TAG_DONE);
  110.  
  111.   if(!(pwc->GUI->LastGadget))
  112.   {
  113.     pwc->Hide(pwc);
  114.     return(FALSE);
  115.   }
  116.  
  117.   winleft=pwc->Prefs->GetLong(pwc->Prefs,"ButtLeft",0);
  118.   wintop=pwc->Prefs->GetLong(pwc->Prefs,"ButtTop",1+pwc->Screen->BarHeight);
  119.  
  120.   if(!(pwc->Window=OpenWindowTags(NULL,WA_Left,winleft,
  121.                                        WA_Top,wintop,
  122.                                        WA_InnerWidth,pwc->GUI->InnerWidth,
  123.                                        WA_InnerHeight,pwc->GUI->InnerHeight,
  124.                                        WA_IDCMP,IDCMP_REFRESHWINDOW|IDCMP_CLOSEWINDOW|pwc->GUI->IDCMP,
  125.                                        WA_SizeGadget,FALSE,WA_DragBar,TRUE,
  126.                                        WA_DepthGadget,TRUE,WA_CloseGadget,TRUE,
  127.                                        WA_NewLookMenus,TRUE,
  128.                                        WA_Activate,FALSE,
  129.                                        WA_Title,"Button settings...",TAG_DONE)))
  130.   {
  131.     pwc->Hide(pwc);
  132.     return(FALSE);
  133.   }
  134.  
  135.   pwc->GUI->Attach(pwc->GUI,pwc->Window);
  136.  
  137.   pwc->Signals=1<<pwc->Window->UserPort->mp_SigBit;
  138.  
  139.   pwc->Visible=TRUE;
  140.   return(TRUE);
  141. }
  142.  
  143.  
  144. void ButtonWin_Hide(struct ButtonWinContext *pwc)
  145. {
  146.   if(pwc->Window)
  147.   {
  148.     pwc->Prefs->SetLong(pwc->Prefs,"ButtTop",pwc->Window->TopEdge);
  149.     pwc->Prefs->SetLong(pwc->Prefs,"ButtLeft",pwc->Window->LeftEdge);
  150.     CloseWindow(pwc->Window);
  151.   }
  152.   pwc->Window=FALSE;
  153.   pwc->Signals=0;
  154.  
  155.   if(pwc->GUI)
  156.     pwc->GUI->Dispose(pwc->GUI);
  157.   pwc->GUI=NULL;
  158.  
  159.   if(pwc->Screen)
  160.     UnlockPubScreen(NULL,pwc->Screen);
  161.   pwc->Screen=FALSE;
  162.  
  163.   if(pwc->Visible)
  164.     pwc->Visible=FALSE;
  165. }
  166.  
  167.  
  168. void ButtonWin_Dispose(struct ButtonWinContext *pwc)
  169. {
  170.   if(pwc)
  171.   {
  172.     if(pwc->Visible)
  173.       pwc->Hide(pwc);
  174.     free(pwc);
  175.   }
  176. }
  177.  
  178.  
  179. struct ButtonWinContext *ButtonWin_Create(struct PrefsGroup *pg)
  180. {
  181.   struct ButtonWinContext *pwc;
  182.   if(!(pwc=malloc(sizeof(struct ButtonWinContext))))
  183.     return(NULL);
  184.   memset(pwc,0,sizeof(struct ButtonWinContext));
  185.   pwc->Dispose=ButtonWin_Dispose;
  186.   pwc->Handle=ButtonWin_Handle;
  187.   pwc->Hide=ButtonWin_Hide;
  188.   pwc->Show=ButtonWin_Show;
  189.  
  190.   pwc->Prefs=pg;
  191.  
  192.   return(pwc);
  193. }
  194.  
  195.  
  196. BOOL ButtonWin_Handle(struct ButtonWinContext *pwc,unsigned long sigs)
  197. {
  198.   BOOL cont=TRUE,close=FALSE;
  199.   long value;
  200.   char *string;
  201.   if(pwc)
  202.   {
  203.     if(sigs&pwc->Signals)
  204.     {
  205.       struct IntuiMessage *im;
  206.       while(im=GT_GetIMsg(pwc->Window->UserPort))
  207.       {
  208.         int class,code,id;
  209.         struct Gadget *gg;
  210.         class=im->Class;
  211.         code=im->Code;
  212.         switch(class)
  213.         {
  214.           case IDCMP_GADGETUP:
  215.             gg=(struct Gadget *)im->IAddress;
  216.             id=gg->GadgetID;
  217.             GT_ReplyIMsg(im);
  218.             switch(id)
  219.             {
  220.               case MIDCLICK_ID:
  221.                 GT_GetGadgetAttrs(gg,pwc->Window,NULL,GTCY_Active,&value,TAG_DONE);
  222.                 pwc->Prefs->SetLong(pwc->Prefs,"MidClick",value);
  223.                 MyWM->MidButton.ClickMode=value;
  224.                 break;
  225.               case MIDCLICKROLL_ID:
  226.                 GT_GetGadgetAttrs(gg,pwc->Window,NULL,GTCY_Active,&value,TAG_DONE);
  227.                 pwc->Prefs->SetLong(pwc->Prefs,"MidCRoll",value);
  228.                 MyWM->MidButton.ClickRollMode=value;
  229.                 break;
  230.               case MIDDOUBLECLICK_ID:
  231.                 GT_GetGadgetAttrs(gg,pwc->Window,NULL,GTCY_Active,&value,TAG_DONE);
  232.                 pwc->Prefs->SetLong(pwc->Prefs,"MidDClick",value);
  233.                 MyWM->MidButton.DoubleClickMode=value;
  234.                 break;
  235.               case FOURTHCLICK_ID:
  236.                 GT_GetGadgetAttrs(gg,pwc->Window,NULL,GTCY_Active,&value,TAG_DONE);
  237.                 pwc->Prefs->SetLong(pwc->Prefs,"4thClick",value);
  238.                 MyWM->FourthButton.ClickMode=value;
  239.                 break;
  240.               case FOURTHCLICKROLL_ID:
  241.                 GT_GetGadgetAttrs(gg,pwc->Window,NULL,GTCY_Active,&value,TAG_DONE);
  242.                 pwc->Prefs->SetLong(pwc->Prefs,"4thCRoll",value);
  243.                 MyWM->FourthButton.ClickRollMode=value;
  244.                 break;
  245.               case FOURTHDOUBLECLICK_ID:
  246.                 GT_GetGadgetAttrs(gg,pwc->Window,NULL,GTCY_Active,&value,TAG_DONE);
  247.                 pwc->Prefs->SetLong(pwc->Prefs,"4thDClick",value);
  248.                 MyWM->FourthButton.DoubleClickMode=value;
  249.                 break;
  250.             }
  251.             break;
  252.           case IDCMP_CLOSEWINDOW:
  253.             GT_ReplyIMsg(im);
  254.             close=TRUE;
  255.             break;
  256.           case IDCMP_REFRESHWINDOW:
  257.             GT_ReplyIMsg(im);
  258.             GT_BeginRefresh(pwc->Window);
  259.             GT_EndRefresh(pwc->Window, TRUE);
  260.             break;
  261.           default:
  262.             GT_ReplyIMsg(im);
  263.             break;
  264.         }
  265.       }
  266.     }
  267.   }
  268.   if(close)
  269.     pwc->Hide(pwc);
  270.   return(cont);
  271. }
  272.  
  273.